﻿using System;

using System.Collections.Generic;
using System.IO;
using System.Text;
using Silvermoon.Controls;
using Silvermoon.Controls.Classes;
using Silvermoon.Animations;
using System.Drawing;
using System.Xml;
using MelectricComponents;

namespace FileExplorer
{
    public class AddFoodWindow : Window
    {
        private Toolbar toolbar;
        private BackgroundDecorator background;
        TextBox txtFood;
        TextBox txtDateTime;
        public AddFoodWindow()
            : base()
        {
            this.Flags = ControlFlags.IgnoreChildClipping;
            background = new BackgroundDecorator { Color = System.Drawing.Color.Silver };
            background.Margin = new Margin(0);
            Controls.Add(background);

            txtFood = new TextBox
                                    {
                                        Alpha = 128
                                        ,
                                        Height = 100
                                        ,
                                        Width = Screen.Size.Width / 8 * 5
                                        ,
                                        Font = new Silvermoon.OpenGL.FontSprite(new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold))
                                        ,
                                        Location = new Point(0, 100)
                                    };
            Controls.Add(txtFood);
            Label lblFood = new Label
                                    {
                                        Text = "Food"
                                        ,
                                        Alpha = 128
                                        ,
                                        Height = 100
                                        ,
                                        Width = Screen.Size.Width / 8 * 3
                                        ,
                                        Location = new Point(Screen.Size.Width / 8 * 5, 100)
                                        ,
                                        Font = new Silvermoon.OpenGL.FontSprite(new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold))
                                    };
            Controls.Add(lblFood);
            txtDateTime = new TextBox
                                        {
                                           Alpha = 128
                                           ,
                                           ToolTip = new DatePickerToolTip()
                                           ,
                                           Size = new Size(Screen.Width, 100)
                                           ,
                                           Location = new Point(0, 0)
                                           ,
                                           Text = DateTime.Now.ToString("dd/MM/yyyy")
                                        };
            Controls.Add(txtDateTime);

            toolbar = new Toolbar();
            Toolbar = toolbar;
            toolbar.LeftButton.Text = "Cancel";
            toolbar.RightButton.Text = "Submit";
            toolbar.LeftButton.Click += (s, e) => { Hide(TransitionMode.ZoomOut); };
            toolbar.RightButton.Click += (s, e) => { SaveData(); };
        }
        private void SaveData()
        {
            Dictionary<string, string> Attributes = new Dictionary<string, string>();
            Attributes.Add("DateTime", txtDateTime.Text);
            Attributes.Add("Food", txtFood.Text);
            XMLUtility oXMLUtility = new XMLUtility();
            oXMLUtility.SaveXML("Food", "Item", Attributes);

            string sFood = txtFood.Text;

            txtFood.Text = "";

            ConfirmDialog dlg = new ConfirmDialog("Food Complete", sFood + " Eaten", true);
            dlg.Margin = new Margin(0, null, 0, 0);
            dlg.HideTransition = TransitionMode.SwipeOutToBottom;
            dlg.ShowModal(TransitionMode.SwipeInFromBottom, (s, e) =>
            {
                Hide(TransitionMode.ZoomOut);
            });
        }
    }
}
